package com.DongBing.service.impl;

import com.DongBing.common.utils.Res;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.val;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.DongBing.common.utils.PageUtils;
import com.DongBing.common.utils.Query;

import com.DongBing.dao.BrandDao;
import com.DongBing.entity.BrandEntity;
import com.DongBing.service.BrandService;
import org.springframework.util.ObjectUtils;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        val key = (String) params.get("key");
        val wrapper = new LambdaQueryWrapper<BrandEntity>();
        wrapper.eq(!ObjectUtils.isEmpty(key),BrandEntity::getBrandId,key);
        wrapper.or().like(!ObjectUtils.isEmpty(key),BrandEntity::getName,key);
        val page = this.page(
                new Query<BrandEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public Res<?> delete(String id) {
        val i = baseMapper.deleteById(id);
        if (i==1) {
            return Res.success("删除成功");
        }
        return Res.error("删除失败");
    }

}
